<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width"/>
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>项目详情</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/main.css" />
    <link rel="stylesheet" type="text/css" href="../../css/project.css" />
</head>
<body>
  <div id="header">
      <div id="back"></div>
      <h3>项目详情</h3>
  </div>
  <div id="all" class="project_detail">
    <div class="list">
      <div class="project_company">
        <div class="left">
          <img src="../../image/technology.png" class="company_logo"/>
        </div>
        <div class="left">
            <div class="enterpriseName"></div>
            <!-- <div class="hot_tags"><span></span></div> -->
            <!-- <div class="evaluate">已有<span class="blue">50</span>名用户对该企业进行了评价</div> -->
         </div>
        </div>
         <div class="project_name">
           <span>项目名称：</span><span id="projectName"></span>
         </div>
         <div class="project_detail">
           <span>招募岗位：</span><span id="positionName"></span><span>招募人数：</span><span id="maxNumber"></span><span>当前人数：</span><span id="nowNumber"></span>
         </div>
         <br>
         <div class="project_detail">
           <span>创建时间：</span><span class="blue" id="createTime"></span>
         </div>
         <div class="project_detail">
           <span>项目状态：</span><span class="blue" id="projectStatus"></span>
         </div>
    </div>
    <div class="box">
      <div class="label"><img src="../../image/job_icon.png"/>项目详情</div>
      <div class="job_detail">
      </div>
    </div>
    <h3 class="partingline">企业评价</h3>
    <div class="evaluation">
    </div>
     <h3 class="partingline">精彩评论</h3>
  <div class="bt">
  </div>
  </div>

  <div class="job_contact">
    <button class="job_btn defalut send">发送简历</button>
    <button class="job_btn info chat">和TA聊聊</button>
    <button class="job_btn Comment">点击评论</button>
  </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/jquery.js"></script>
<script type="text/javascript">
apiready=function(){
var projectId,postId=0;
var userHeaderImageUrl=$api.getStorage("userHeaderImageUrl");
var scrollAll_Div = document.getElementById("all");
var sourcePath = "widget://image/emotion";//表情存放目录
var count=1;
var faker=false;
  //ajax查询这个职位的详情
  var positionId= api.pageParam.positionId;
  var isSendCV=api.pageParam.status;
  var logo=api.pageParam.logo;
  var enterpriseName=api.pageParam.enterpriseName;
  var projectName=api.pageParam.projectName;
  var currentTotal=api.pageParam.currentTotal;
  var total=api.pageParam.total;
  var name=api.pageParam.name;
  var projectStatus=api.pageParam.projectStatus;
  $(".company_logo").attr("src",logo);
  $(".enterpriseName").html(enterpriseName);
  $("#projectName").html(projectName);
  if(isSendCV!='申请'){
    $(".send").html("已投递");
  }
  var url='/student/position/'+positionId;
  var functionRet=function(ret){
    if(ret.code==0){
      $("#createTime").html((ret.data.created).replace(/T/g," ").substring(0,ret.data.created.length-9));
     // $("#businessName").html(ret.businessName);
      $("#positionName").html(name);
      $("#maxNumber").html(total);
      $("#nowNumber").html(currentTotal);
      $("#projectStatus").html(projectStatus);
      $(".job_detail").html(ret.data.projectIntroduction+ret.data.projectContent);
      projectId=ret.data.projectId;
      projectManager=ret.data.stuManagers;
    }
    getComment(1,10,false);
    getEvaluation(positionId);
    //$("#businessName").html(ret.businessName);
    //$("#businessName").html(ret.businessName);
  }
  var functionErr=function(err){

  }
  //获取公司和职位详情
  getNew(url,functionRet,functionErr);

  //发送简历
  $(".send").on("touchstart",function(){
    if($(".send").html()=="已投递"){

    }else{
      //判断项目是否已完成
      if($("#projectStatus").html() == '已完成'){
        toast("项目已完成，无法投递简历","middle")
      }else{
        var dialogBox = api.require('dialogBox');
        dialogBox.input({
            texts: {
                title: '投递简历',
                placeholder: '一句话介绍你自己',
                leftBtnTitle: '取消',
                rightBtnTitle: '确定'
            },
            styles: {
                bg: '#fff',
                corner: 4,
                h: 200,
                title: {
                    h: 45,
                    alignment: 'center',
                    size: 16,
                    color:'#838c94'
                },
                input: {
                    h: 32,
                    y:50,
                    marginT: 6,
                    textSize: 14,
                    textColor: '#000'
                },
                dividingLine: {
                    width: 0.5,
                    color: '#838c94'
                },
                left: {
                    bg: '#f3f3f3',
                    color: '#838c94',
                    size: 14
                },
                right: {
                    bg: '#37acfe',
                    color: '#fff',
                    size: 14
                }
            }
        }, function(ret) {
            if (ret.eventType == 'left') {
                var dialogBox = api.require('dialogBox');
                dialogBox.close({
                    dialogName: 'input'
                });
            }
            if (ret.eventType == 'right') {
                //一句话介绍自己
                var techIntr=ret.text;
                var url='/student/apply/position';
                var data={
                  "positionId": positionId,
                  "introduction": techIntr
                };
                var functionRet=function(ret){
                  if(ret.code==0){
                    $(".send").html("已投递");
                    api.alert({
                        msg: '您已成功投递该项目，等待企业回复',
                    });
                    var dialogBox = api.require('dialogBox');
                    dialogBox.close({
                        dialogName: 'input'
                    });
                    //刷新首页
                    api.execScript({
                      name: 'root',
                      frameName: 'frame1',
                      script: 'history.go(0)'
                  });
                  }else{
                    toast("投递失败，请重新投递","bottom");
                  }
                }
                var functionErr=function(err){

                }
                //ajax提交投递简历请求
                if(techIntr==""){
                  api.alert({
                      msg: '请输入一句话介绍自己',
                  });
                }else{
                  postNew(url,data,functionRet,functionErr);
                }
            }
        });
      }
    }
    });
    //和他聊聊
    $(".chat").on("touchstart",function(){
      //  var businessId=$("#businessName").attr("businessId");
        api.openWin({
                name: 'detail_frame',
                url: 'detail_frame.html',
                pageParam: {
                    projectManager: projectManager
                }
            });
      });
    //点击公司，跳转到公司详情页面
    // $(".project_company").on("touchstart",function(){
    //   var businessId=$("#businessName").attr("businessId");
    //   api.openWin({
    //       name: 'company',
    //       url: 'company.html',
    //       pageParam: {
    //           businessId: businessId,
    //           logo:logo,
    //           // isSendCV:isSendCV
    //       }
    //   });
    //     // openPage("company","company.html");
    // });
//------------------------------------------------------------------------
//评论模块代码
//------------------------------------------------------------------------
//点击出现评论输入框
var UIChatBox = api.require('UIChatBox');
$(".Comment").on("click",function(){
  postId=0;
  UIChatBox.show();
});
//点击屏幕隐藏评论输入框
$("#all").on("touchstart",function(){
  UIChatBox.hide();
});

var aid=$api.getStorage("aid");
var flag=$api.getStorage("flag");
//打开输入框模块
  UIChatBox.open({
  placeholder: '请输入评论...',
  emotionPath: 'widget://image/emotion',
  maxRows: 4,
  texts: {
      sendBtn: {
          title: 'send'
      }
  },
  styles: {
      inputBar: {
          borderColor: '#d9d9d9',
          bgColor: '#f2f2f2'
      },
      emotionBtn: {
          normalImg: 'widget://image/face.png'
      },
      inputBox: {
          borderColor: '#B3B3B3',
          bgColor: '#FFFFFF'
      },
      sendBtn: {
          titleColor: '#4cc518',
          bg: '#999999',
          activeBg: '#46a91e',
          titleSize: 14
      }
  }
}, function(ret, err) {
  if(ret.eventType=="send"){
    if(ret.msg){
      issueComment(ret.msg);
    }
  }
});
//先把输入框隐藏
UIChatBox.hide();
//----------------------------------------------------------------------------------------------
//创建评论
function issueComment (msg){
  var msgUrl="/student/post";
  var data={
  "content": msg,
  "projectId": projectId,
  "postId": postId
  }
  var functionRet=function(ret1){
    if(ret1.code==0){
      if(count<0){
          count=0;
      }
        //将评论显示在页面上
        //置底操作
         faker=true;
         $(".bt").html("");
         getComment(1,10*(count+1),faker);
        UIChatBox.hide();
        scroll_top();

      }else{
        toast("评论失败","bottom");
        return false;
      }
    }

  var functionErr=function(err1){

  }
  postNew(msgUrl,data,functionRet,functionErr);
}
//----------------------------------------------------------------------------------------------
//获取企业评价
function getEvaluation(positionId){
  var url='/student/evaluation/'+positionId;
  var functionRet=function(ret){
    var json=ret.data;
    if(ret.code==0){
      if($.isEmptyObject(ret.data)){
          $(".evaluation").append('<div>暂无评价</div>');
      }else{
        var evaluation=ret.data.evaluation;
        if(evaluation==null){
          evaluation='无'
        }
          $(".evaluation").append('<div><span>评价时间:</span><span>'+(ret.data.created).replace(/T/g," ").substring(0,ret.data.created.length-9)+'</span></div><div><span>评价内容:</span><span>'+evaluation+'</span></div>');
      }
    }else{
      toast("获取企业评价失败","bottom");
    }
  }
  var functionErr=function(err1){
  }
  getNew(url,functionRet,functionErr);
}
//获取评论

function getComment(page,size,faker){
  var jwt=$api.getStorage('jwt');
  api.ajax({
    url: 'http://47.104.170.122/v1/portal/schoolEnterprise/student/project/posts?projectId='+projectId+"&pageNum="+1+"&pageSize="+size+'&token='+jwt,
    method: 'GET',
    headers: {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Headers": "Authorization",
      "Content-Type" : 'application/json; charset=utf-8'
    }
  }, function(ret, err) {
    if(ret.code==0){
      if(ret.data){
          for (var i = 0; i < ret.data.length; i++) {
            var talk_content=transText(ret.data[i].content);
            var dateStr = (ret.data[i].created.replace(/T/g," ")).substring(0,ret.data[i].created.length-9);
            $(".bt").append('<div class="commentBox"><div class="comment" postId="'+ret.data[i].id+'"><div class="reply_c"><img src='+ret.data[i].avatarUrl+'><span class="commentName">'+ret.data[i].name+'</span></div><div class="commentFont"><span>'+talk_content+'</span></div><span class="reply">回复</span><div class="ct"><div class="created">'+dateStr+'</div></div></div>');
            //查询回帖
              $.ajax({
                async: false,
                type : "GET",
                url: 'http://47.104.170.122/v1/portal/schoolEnterprise/student/posts/'+ret.data[i].id+'?token='+jwt,
                success: function(rets){
                  if(rets.data){
                    for(var j=0;j<rets.data.length;j++){
                      $(".commentBox").eq(i).append('<div class="comment" style="padding-left:40px;" postId="'+ret.data[j].id+'"><div class="reply_c"><img src='+rets.data[j].avatarUrl+'><span class="commentName">'+rets.data[j].name+'</span></div><div class="commentFont"><span>'+transText(rets.data[j].content)+'</span></div><div class="ct"><div class="created">'+(rets.data[j].created.replace(/T/g," ")).substring(0,rets.data[j].created.length-9)+'</div></div>')
                      }
                  }
                  }});
          }
          if(faker){
            scroll_top();
            faker=false;
          }
        }else{
          count--;
        }
    }else{
      toast("获取评论失败","bottom");
    }
  });
}
//-------------------------------------------------------------
//点击回复按钮
var UIChatBox = api.require('UIChatBox');
$(".bt").on("click",".reply",function(){
  postId=$(this).closest(".comment").attr("postId");
    UIChatBox.show();
    UIChatBox.insertValue({
      index: 0,
      msg:'@'+$(this).closest(".bt").find('.commentName').html()
    });
});
//--------------------------------------------------------------------------------------
//表情转换
function transText(text, imgWidth, imgHeight){
    var imgWidth = imgWidth || 30;
    var imgHeight = imgHeight || 30;
    var regx = /\[(.*?)\]/gm;
    var textTransed = text.replace(regx,function(match){
        var imgSrc = emotionData[match];
        if(!imgSrc){
                //说明不对应任何表情，直接返回
                return match;
        }
        var img = "<img src="+imgSrc+" width="+imgWidth+" height="+imgHeight+">";
        return img;
    });
    return textTransed;
}

getImgsPaths(sourcePath, function (emotion) {
      emotionData = emotion;
});
function getImgsPaths(sourcePathOfChatBox, callback){
var jsonPath = "widget://image/emotion/emotion.json";//表情的JSON数组
api.readFile({
    path: jsonPath
    },function(ret,err){
        if(ret.status){
            var emotionArray = JSON.parse(ret.data);
            var emotion = {};
            for(var idx in emotionArray){
                    var emotionItem = emotionArray[idx];
                    var emotionText = emotionItem["text"];
                    var emotionUrl = "../../image/emotion/"+emotionItem["name"]+".png";
                    emotion[emotionText] = emotionUrl;
            }
            /*把emotion对象 回调出去*/
            if("function" === typeof(callback)){
                    callback(emotion);
            }
        }
    });
}
//---------------------------------------------------------------------------------------------
//当滚动条置底时加载数据
//每10条加载一次数据
 $("#all").scroll(function(){
 var viewH =$(this).height();//可见高度
 var contentH =$(this).get(0).scrollHeight;//内容高度
 var scrollTop =$(this).scrollTop();//滚动高度

 if(scrollTop/(contentH -viewH)>=0.9){ //到达底部5%以内,加载新内容
 // 这里加载数据..
 count++;
//getComment(count,10,faker);

 }
 });
 //---------------------------------------------------------------------------------------------
 function scroll_top(){
    scrollAll_Div.scrollTop=scrollAll_Div.scrollHeight;
    //console.log("dd:  "+scrollAll_Div.scrollHeight);
  }
//----------------------------------------------------------------------------------
//刪除評論
// function deleteContent(id){
//
//     //var msgUrl="/api/public-msg-comments/{id}?path="+id;
//      var data={
//     //   "aid": aid
//     //    //"id": id
//      };
//     var msgUrl="/api/pa-project-chat/"+id+"?aid="+aid;
//     var functionRet=function(ret1){
//     }
//     var functionErr=function(err1){
//       if(err1.statusCode==200){
//
//         //将点击删除按钮时的滚动条高度记下
//         var height=scrollAll_Div.scrollTop;
//         alert("评论删除成功！");
//         //window.location.reload();
//         $(".bt").html("");
//         getComment(1,10*(count+1),faker);
//         //删除评论后评论区会置顶
//         //所以将之前记下的高度赋值给滚动条，让它返回之前的高度
//         scrollAll_Div.scrollTop=height;
//       }
//     }
//     deleteData(msgUrl,data,functionRet,functionErr);
// }
//-------------------------------------------------------------------------------------------
 //点击删除按钮
 // $(".bt").on("click",".delete",function(){
 //   if(aid== $(this).attr('commentsAid-id')){
 //       deleteContent($(this).attr('comment-id'));
 //   }else if(flag==7){
 //        var id = $(this).attr('comment-id');
 //        var data={
 //       //   "aid": aid
 //       //    //"id": id
 //        };
 //       var msgUrl="/api/pa-project-chat/"+id+"/del";
 //       var functionRet=function(ret1){
 //       }
 //       var functionErr=function(err1){
 //         if(err1.statusCode==200){
 //
 //           //将点击删除按钮时的滚动条高度记下
 //           var height=scrollAll_Div.scrollTop;
 //           alert("评论删除成功！");
 //           //window.location.reload();
 //           $(".bt").html("");
 //           getComment(1,10*(count+1),faker);
 //           //删除评论后评论区会置顶
 //           //所以将之前记下的高度赋值给滚动条，让它返回之前的高度
 //           scrollAll_Div.scrollTop=height;
 //         }
 //       }
 //       deleteData(msgUrl,data,functionRet,functionErr);
 //   }else{
 //     alert("不能删除别人的评论！");
 //   }
 // });
 //--------------------------------------------------------------------------------------
//监听输入框所在区域弹动事件
// var UIChatBox = api.require('UIChatBox');
// UIChatBox.addEventListener({
//     target: 'inputBar',
//     name: 'move'
// }, function(ret, err) {

//       if(ret.panelHeight>100){

//         //scroll_top();
//       //当点击输入框时 ，聊天框定位想上弹起
//         var _h=ret.panelHeight+"px";
//         //判断系统类型
//         //  var systemType = api.systemType;
//         //if(systemType=='android'){
//         //安卓
//         //  $("#all").css("bottom",40);
//         //}else{
//         //ios
//         scrollAll_Div.style.bottom=_h;
//         scrollAll_Div.style.top=ret.panelHeight*(-1)+'px';
//         //alert("ddd"+scrollAll_Div.style.bottom)
//         //}
//           console.log(scrollAll_Div.style.bottom);
//     }else{
//         scrollAll_Div.style.bottom='56px';
//         scrollAll_Div.style.top='60px';
//     }

// });

}
//jquery
$(function(){
  back();
})
</script>
<script type="text/javascript" src="../../script/main.js"></script>
</html>
